#ifndef _CCTRANSFORM_H_
#define _CCTRANSFORM_H_

#include "CCSpineObject.h"
#include "ccTypes.h"

NS_CC_BEGIN

class CCSkeletalSprite;

/**
 * transform base class
 */
class CCTransform : public CCSpineObject {
public:
	/// interpolator type
	enum InterpolatorType {
		/// linear change
		LINEAR=0,
		
		/// change in a bezier style, controled by two control points
		BEZIER,
		
		/// instantly changed at the end
		STEP
	};
    
    static const int _SEGMENTS_NUM=10;
	
	/// interpolator
	struct Interpolator {
		/// type
		InterpolatorType type;
        float dfx,dfy;
        float ddfx,ddfy;
        float dddfx,dddfy;
        
        void set(float cp1X,float cp1Y,float cp2X,float cp2Y);
	};
	
	/// key frame base
	struct KeyFrame {
		/// time
		float time;
		
		/// interpolator
		Interpolator interpolator;
		
		/// true means this key frame is valid
		bool valid;
	};
	
protected:
	CCTransform();
	
	/// get interpolation time, from 0 to 1
	float getInterpolationTime(float startTime, float endTime, float curTime,const Interpolator& interpolator);
	
public:
	virtual ~CCTransform();
	
	/// calculate current frame
	virtual void populateFrame(float time, float deltaTime) = 0;
	
	/**
	 * apply current frame to a skeleton
	 *
	 * @param owner the target to apply transform
	 * @return true if frame is applied, or false if not applied
	 */
	virtual void applyTo(CCSkeletalSprite* owner,float alpha=1) = 0;
};

NS_CC_END

#endif
